<?php

class Application_Form_ProveedorConsumo extends Sgit_Form
{
    
    public function init_form()
    {
        
         $request = Zend_Controller_Front::getInstance()->getRequest();

         
         $file[1] = Sgit_Util_FileUpload::run('factura_proveedor',$request->getParam('idZona'));
         if(!file_exists($file[1]['dir'])) mkdir($file[1]['dir']);
         
         
         $id=$request->getParam('id');
         
        

         $proveedor=new Sgit_Form_Element_Select_Proveedores('id_proveedor');
         $proveedor ->setLabel('Proveedor')->setRequired(true);
         $this->addElement($proveedor);     
          
          
         $anno=new Sgit_Form_Element_Select_Year('anno');
         $anno->setRequired(true)->setLabel('Año Contable');
         $this->addElement($anno);    
          
         $mes=new Sgit_Form_Element_Select_Mes('mes');
         $mes->setRequired(true)->setLabel('Mes Contable');
         $this->addElement($mes);    


         $consumo=new Sgit_Form_Element_NumNull('consumo');
         $consumo->setLabel('Consumo kWh')->setRequired(true);
         $this->addElement($consumo);     
          
          
         $importe=new Sgit_Form_Element_NumNull('importe');
         $importe->setLabel('Importe €')->setRequired(true);
         $this->addElement($importe);   


         $potencia_max=new Sgit_Form_Element_NumNull('potencia_max');
         $potencia_max->setLabel('Potencia Max kW');
         $this->addElement($potencia_max);   

        
         $files[0]=new Zend_Form_Element_File($file[1]['name']);
         $files[0]->setLabel('Adjunto')
                ->setDestination($file[1]['dir'])
                ->addValidator('Size', false, 31457280)
                ->setValueDisabled(true); 
         $this->addElement($files[0]);


        if($id){
             $options=Sgit_Util_GetFiles::run($file[1]['tabla'],$file[1]['key'],$id);
             
             if($options){
                 $files_lista1 = new Zend_Form_Element_MultiCheckbox($file[1]['activo']);
                 $files_lista1->setMultiOptions($options)
                    ->setLabel('Borrar Adjunto')
                    ->setAttrib('size',25); 
                 $this->addElement($files_lista1);
             }
         }
         


      

  
       $this->setElementDecorators(array(
		    'ViewHelper',
		   'Errors',
		    array(array('data' => 'HtmlTag'),	array('tag' => 'td', 'class' => 'element')   ),
		    array('Label', array('tag' => 'td')),
		    array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
	   ));
       
       
 
          //fix file 
       $files[0]->setDecorators(
            array(
                'File',
                'Errors',
                array(array('data' => 'HtmlTag'), array('tag' => 'td','class' => 'element')),
                array('Label', array('tag' => 'td')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
            )
        );
    



    }
}
